package com.huiquan.elasticsearch;

import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.net.InetSocketAddress;


@Configuration
public class ElasticsearchAplication {

    @Value("${elasticsearch.host}")
    private String elasticsearchHost;

    @Bean
    public TransportClient client(){
        InetSocketTransportAddress node = new InetSocketTransportAddress(
                new InetSocketAddress(elasticsearchHost,9300)
        );
        //设置集群名字
        Settings settings = Settings.settingsBuilder()
                .put("cluster.name", "huiquan")
                .build();
        TransportClient client = new TransportClient.Builder().settings(settings).build()
                .addTransportAddress(node);
        return client;
    }
}